$(function(){
	
	var options = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
 
        dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type) 
        clearForm: false        // clear all form fields after successful submit 

    }; 
 

    $('#form_task').submit(function() { 

        $(this).ajaxSubmit(options); 

        return false; 
    }); 
    
    //取消任务单
    var $btnCancel = $('#btnCancel');
    
    $btnCancel.click(function(){
    	
    	if(!confirm('确认要取消任务单?')){
    		return false;
    	}
    	
    	$('#ts_-1').click();
    	$('#form_task').submit();
    	
    });
    
});


function showRequest(formData, jqForm, options) { 
    //var queryString = $.param(formData); 
    return true; 
} 

function showResponse(data, statusText, xhr, $form)  { 
	
	
	if(data.success){
		alert(data.message);
		var form = $form.attr('id');

		if(form == 'form_task'){
			
			var referer = $('#referer').val();
			
			if(referer != ''){
				location.href = referer;'/index.php/Admin/Task/';
			}else{
				location.href = '/index.php/Admin/Task/';
			}
		}
		
		
	}else{
		alert(data.message);
	}
}